package sk.stuba.fiit.ltasys.web.mvc.model.entity;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

/**
 * ARCHIVE_PACKAGE Entity.
 * 
 * @author Marek Hruska
 */

@Entity
@Table(name = "ARCHIVE_PACKAGE")
public class ArchivePackageEntity {
	
	public static final transient String TOKEN = "token";
	public static final transient String USER = "user";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int archive_id;
	
	@OneToOne
	@LazyToOne(LazyToOneOption.FALSE)
	@Cascade({CascadeType.ALL})
	private UserDataEntity userData = null;
	private String token = null;
	
	@OneToMany
	@Cascade({CascadeType.ALL})
	@JoinColumn(name="evidenc_rec_id")
	@LazyCollection(LazyCollectionOption.FALSE)
	private Set<EvidenceRecordEntity> archiveRecord = null;	
	
	@OneToOne
	@LazyToOne(LazyToOneOption.FALSE)
	@JoinColumn(name = "user_id")
	private UserEntity user = null;
	
	private String name;
	private String description;
	
	public ArchivePackageEntity() {}
	
	public int getArchive_id() {
		return archive_id;
	}

	public void setArchive_id(int archive_id) {
		this.archive_id = archive_id;
	}



	public UserDataEntity getUserData() {
		return userData;
	}

	public void setUserData(UserDataEntity userData) {
		this.userData = userData;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public Set<EvidenceRecordEntity> getArchiveRecord() {
		return archiveRecord;
	}

	public void setArchiveRecord(Set<EvidenceRecordEntity> archiveRecord) {
		this.archiveRecord = archiveRecord;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public UserEntity getUser() {
		return user;
	}

	public void setUser(UserEntity user) {
		this.user = user;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + archive_id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ArchivePackageEntity other = (ArchivePackageEntity) obj;
		if (archive_id != other.archive_id)
			return false;
		return true;
	}
}
